package cc.bailongma.me;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.TextView;

public class Regist2Activity extends Activity implements OnClickListener {
	private Intent intent;

	private EditText et_login_phone ;
	private EditText et_login_password;
	private EditText et_decive_sim;
	private EditText et_confire_sim;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_regist_step2);
		intent = getIntent();
		setView();
	}

	private void setView() {
		TextView tv_device_number = (TextView) findViewById(R.id.tv_device_number);
		tv_device_number.setText(intent.getStringExtra("number"));
		et_login_phone = (EditText) findViewById(R.id.et_login_phone);
		et_login_password = (EditText) findViewById(R.id.et_login_password);
		et_decive_sim = (EditText) findViewById(R.id.et_decive_sim);
		et_confire_sim = (EditText) findViewById(R.id.et_confire_sim);
		findViewById(R.id.tv_reg).setOnClickListener(this);
		findViewById(R.id.tv_back).setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.tv_reg:
			String phone = et_login_phone.getText().toString().trim();
			String password = et_login_password.getText().toString().trim();
			String decive_sim = et_decive_sim.getText().toString().trim();
			String confire_sim = et_confire_sim.getText().toString().trim();
			if (TextUtils.isEmpty(phone)) {
				et_login_phone.setError("手机不能为空");
				return;
			}
			if (TextUtils.isEmpty(password)) {
				et_login_password.setError("密码不能为空");
				return;
			}
			if (TextUtils.isEmpty(decive_sim)) {
				et_decive_sim.setError("设备sim不能为空");
				return;
			}
			if (TextUtils.isEmpty(confire_sim)) {
				et_confire_sim.setError("设备sim不能为空");
				return;
			}
			if(!confire_sim.equals(decive_sim)){
				et_confire_sim.setError("设备sim不一致");
				return;
			}
			Intent intent=new Intent(this,RegistResultActivity.class);
			intent.putExtra("phone", phone);
			intent.putExtra("password", password);
			intent.putExtra("decive_sim", decive_sim);
			intent.putExtra("confire_sim", confire_sim);
			startActivity(intent);
			finish();
			break;
		case R.id.tv_back:
			startAty(LoginActivity.class);
			break;
		case R.id.tv_forget_pwd:
			startAty(FindPwdActivity.class);
			break;
		}

	}
	private void startAty(Class<?> clz) {
		Intent intent=new Intent(this,clz);
		startActivity(intent);
		finish();
	}
}
